//
// Created by Asus on 2025/6/2.
//

#include <algorithm>
#include <iostream>
#include <vector>
#include <bits/ostream.tcc>
using namespace std;

void demo01() {
    negate<int> negate;
    cout << negate(50) << endl;
    plus<int> plus;
    cout << plus(5, 10) << endl;
    minus<int> minus;
    cout << minus(5, 10) << endl;
}

class MyCompare
{
public:
    bool operator()(int v1,int v2) const
    {
        return v1 > v2;
    }
};

void demo02() {
    vector<int> v;

    v.push_back(10);
    v.push_back(30);
    v.push_back(50);
    v.push_back(40);
    v.push_back(20);
    for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
    //自己实现仿函数
    //sort(v.begin(), v.end(), MyCompare());
    //STL内建仿函数  大于仿函数
    sort(v.begin(), v.end(), greater<int>());
    for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
}

void demo03() {
    vector<bool> v;
    v.push_back(true);
    v.push_back(false);
    v.push_back(true);
    v.push_back(false);

    for (vector<bool>::iterator it = v.begin();it!= v.end();it++)
    {
        cout << *it << " ";
    }
    cout << endl;

    //逻辑非  将v容器搬运到v2中，并执行逻辑非运算
    vector<bool> v2;
    v2.resize(v.size());
    transform(v.begin(), v.end(),  v2.begin(), logical_not<bool>());
    for (vector<bool>::iterator it = v2.begin(); it != v2.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;

    vector<bool> a = {true, false, true};
    vector<bool> b = {false, true, true};
    vector<bool> result(a.size());
    vector<bool> result2(a.size());
    // 逐元素执行逻辑或：a[i] || b[i]
    transform(a.begin(), a.end(), b.begin(), result.begin(), logical_or<bool>());
    transform(a.begin(), a.end(), b.begin(), result2.begin(), logical_and<bool>());
    // 输出: 1 1 1
    for (bool b : result) cout << b << " ";
    for (bool b : result2) cout << b << " ";
}

int main(int argc, char *argv[]) {
    // demo01();
    // demo02();
    demo03();
    return 0;
}
